package jdbc;

import java.sql.*;

public class JDBCDemo1 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        System.out.println("正在连接数据库...");
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3308/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "root");
        System.out.println("数据库连接成功！");
        Statement statement = connection.createStatement();
        String sql = "CREATE TABLE user(" +
                     "id INT PRIMARY KEY AUTO_INCREMENT," +
                     "username VARCHAR(30)," +
                     "password VARCHAR(30)," +
                     "nickname VARCHAR(30)," +
                     "age INT(3)" +
                     ")";
        statement.execute(sql);
        System.out.println("表创建成功");
        connection.close();
    }
}
